function combine(a: number, b: number): number;
function combine(a: string, b: string): string;
function combine(a: number | string, b: number | string) {
  if (typeof a === "number" && typeof b === "number") {
    return a * b;
  } else if (typeof a === "string" && typeof b === "string") {
    return a + b;
  }
  throw new Error("a和必须是相同的类型");
}

console.log(combine(1, 2));
console.log(combine("1", "2"));

// 可选参数：不能出现在前面，只能出现在参数列表末尾
function sum(a: number, b: number, c?: number) {
  return a + b + (c ?? 0);
}

console.log(sum(1, 2, 2));
